<template>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" :class="method==='view'?'readonly':''"  :disabled="method==='view'" @keyup.enter.native="doSubmit()"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="报销日期" prop="reimbursementdate"
                :rules="[
                 ]">
                <el-date-picker
                      v-model="inputForm.reimbursementdate"
                      type="datetime"
                      style="width: 100%;"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="报销类型" prop="accounttype"
                :rules="[
                 ]">
                <el-select v-model="inputForm.accounttype" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('account_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="报销说明" prop="reimbursementinstruction"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.reimbursementinstruction" placeholder="请填写报销说明"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="报销金额" prop="reimbursableamount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.reimbursableamount" placeholder="请填写报销金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="票据张数" prop="ticketnumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.ticketnumber" placeholder="请填写票据张数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="实报金额" prop="actreportmoney"
                :rules="[
                 ]">
              <el-input v-model="inputForm.actreportmoney" placeholder="请填写实报金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="差旅报销" prop="travereimburesement.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择差旅报销"
            labelName = 'procInsId'
            labelValue = 'id'
            :value = "inputForm.travereimburesement.id"
            :limit="1"
            @getValue='(value) => {inputForm.travereimburesement.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'procInsId',
              label: '流程实例id'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'procInsId',
              label: '流程实例id'
            }
            ]"
            dataListUrl="/dlyrl.oa.bussreimb/oaBussinessReimbursement/list"
            entityBeanName="oaBussinessReimbursement"
            queryEntityUrl="/dlyrl.oa.bussreimb/oaBussinessReimbursement/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="非差旅报销" prop="notravereimburesement.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择非差旅报销"
            labelName = 'procInsId'
            labelValue = 'id'
            :value = "inputForm.notravereimburesement.id"
            :limit="1"
            @getValue='(value) => {inputForm.notravereimburesement.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'procInsId',
              label: '流程实例id'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'procInsId',
              label: '流程实例id'
            }
            ]"
            dataListUrl="/dlyrl.oa.unbussreimb/oaUnbussinessReimbursement/list"
            entityBeanName="oaUnbussinessReimbursement"
            queryEntityUrl="/dlyrl.oa.unbussreimb/oaUnbussinessReimbursement/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="核定金额" prop="Approvedmoney"
                :rules="[
                 ]">
              <el-input v-model="inputForm.Approvedmoney" placeholder="请填写核定金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" v-if="method === 'add'" type="primary" @click="continueDoSubmit()">继续添加</el-button>
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" v-if="method !== 'view'" type="primary" @click="doSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        oldInputForm: '',
        inputForm: {
          id: '',
          reimbursementdate: '',
          accounttype: '',
          reimbursementinstruction: '',
          reimbursableamount: '',
          ticketnumber: '',
          actreportmoney: '',
          travereimburesement: {
            id: ''
          },
          notravereimburesement: {
            id: ''
          },
          Approvedmoney: '',
          remarks: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, obj) {
        this.method = method
        if (method === 'add') {
          this.title = `新建报销内容Entity`
        } else if (method === 'edit') {
          this.title = '修改报销内容Entity'
        } else if (method === 'view') {
          this.title = '查看报销内容Entity'
        }
        this.visible = true
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.inputForm.id = ''
          this.oldInputForm = ''
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.oldInputForm = obj
            this.inputForm = JSON.parse(JSON.stringify(obj))
          }
        })
      },
   // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.visible = false
          }
        })
      },
      continueDoSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.$refs['inputForm'].resetFields()
          }
        })
      }
    }
  }
</script>